package com.jiyinit.web.core.activiti.controller;

import com.jiyinit.core.framework.base.entity.ResponseDto;
import com.jiyinit.core.framework.base.util.Check;
import com.jiyinit.core.framework.base.util.JsonEntityTransform;
import com.jiyinit.core.framework.base.util.LogUtil;
import com.jiyinit.web.core.activiti.dto.AttendanceRequest;
import com.jiyinit.web.core.activiti.service.MobileDataStatisticsServiceImpl;
import com.jiyinit.web.core.activiti.vo.AttendanceEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author liuzongguang
 * @date 2018/7/20.
 */
@Controller
@RequestMapping("/mobile/statistics")
public class MobileDataStatisticsContrllor {
    private static Logger logger = LoggerFactory.getLogger(LeaveController.class);


    @Resource(name = "mobileDataStatisticsServiceImpl")
    private MobileDataStatisticsServiceImpl mobileDataStatisticsService;
    /**
     * 手机端考勤情况统计,按照统计时间点统计
     * @author liuzongguang
     * @create 2018/7/20 10:23
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST,value = "getAttendanceInfo")
    public ResponseEntity<ResponseDto> getAttendanceInfo(HttpServletRequest request,@RequestParam String request_json) {
        String logJson = request.getParameter("request_json");
        LogUtil.info(logger, "接口参数:{}", logJson);
        AttendanceRequest attendanceRequest = JsonEntityTransform.json2Object(logJson, AttendanceRequest.class);
        if(Check.isNullStr(attendanceRequest.getOrgId()))
        {
            return new ResponseEntity<>(ResponseDto.responseFail("机构编号不能为空"), HttpStatus.OK);
        }
        if(Check.isNullStr(attendanceRequest.getTimeStamp()))
        {
            return new ResponseEntity<>(ResponseDto.responseFail("数据请求时间不能为空"), HttpStatus.OK);
        }
        List<AttendanceEntity> result =  mobileDataStatisticsService.getAttendanceInfo(attendanceRequest);
        return new ResponseEntity<>( ResponseDto.responseOK(result), HttpStatus.OK);
    }
}
